<template>
  <div class="data-title">
    <h3>{{text}}</h3>
    <div class="data-tabs" v-show="hasTab">
      <div class="data-tabs-list" :class="{'selected':isActive==index}" v-for="(item,index) in tabs"
           @click="selectTablist(index)"
      >
        {{ item.title }}
      </div>
      <el-date-picker
        v-if="isActive==3"
        v-model="time"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      >
      </el-date-picker>
    </div>
  </div>
</template>

<script>
export default {
  name: 'title',
  props: {
    text: {
      type: String,
      default() {
        return '接入情况'
      }
    },
    hasTab: {
      type: Boolean,
      default() {
        return true
      }
    }
  },
  data() {
    return {
      isActive: 0,
      tabs: [
        {
          title: '近一日'
        },
        {
          title: '近一周'
        },
        {
          title: '近一月'
        },
        {
          title: '自定义'
        }
      ],
      time: ''
    }
  },
  methods: {
    selectTablist(index) {
      this.isActive = index;
      this.$emit('selectTablist',index)
    }
  }
}
</script>

<style lang="scss" scoped>
.el-date-editor--daterange.el-input__inner {
  width: 260px !important;
}

.data-title {
  height:60px;
  padding: 10px;
  display: flex;
  align-items: center;

  h3 {
    font-size: 18px;
    margin: 0;
    flex: 1
  }

  .data-tabs {
    display: flex;
    align-items: center;

    .data-tabs-list {
      font-size: 14px;
      padding: 10px 5px;
      margin: 0 5px;
      cursor: pointer;
      border-bottom: 2px solid transparent;
    }
  }
}

.selected {
  border-bottom: 2px solid #4b6eef !important;
}

</style>
